package lancooPaperAnswer;

import android.content.Context;
import android.os.Handler;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;
import com.example.lancooznbk.presenter.PaperDef;

import org.apache.commons.lang3.StringEscapeUtils;

import lancooControl.Control;
import lancooControl.CustomAnswerChoiceView;

import static android.view.View.GONE;
import static testPaperCTCS.GuessTestingPaperActivity.InforGuessTesting;
import static testPaperFavoritesPage.FavoritesPagePaperActivity.InforFavoritesPage;
import static testPaperJBFX.BasicReviewPaperActivity.InforBasicReview;
import static testPaperNDFX.DifficultReviewPaperActivity.InforDifficultReview;
import static testPaperWrong.WrongQuesPaperActivity.InforWrongQues;
import static testPaperWrongHistory.HistoryWrongQuesPaperActivity.InforHistoryWrongQues;


/**
 * 完型选择
 * Created by Administrator on 2017/3/14.
 */
public class AnswerWxxzAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    //当前试题数量
    private int SumItem;
    //当前试题在当前试题的ID
    private int PaperID;
    //当前小题ID
    private int OptionID;
    private Context mContext;

    private int ModelFrom;


    private int tvBlack;
    private int tvBlue;
    private int tvWhite;
    private int tvGreen;
    private int tvRed;
    private int btnWhite;
    private int btnBlue;
    private int btnGreen;
    private int btnRed;

    /*
    * 获取小题选项信息
    * */
    private int state;//试卷的作答状态
    private String isAssess;//本题是否可自评
    private String stuAssess;//自评/机评结果
    private int sumOption;//选项的个数
    private String stuAnswer;//用户答案
    private String answer;//正确答案
    private int itemIndex;//小题数字编号
    private String itemContent;//小题题目信息
    private double score;//试题总分值
    private String analysis;//答案解析
    private int totalItemCount;//小题数量

    private String[] optionIndex;//选项号所对应的文字
    private String[] option;//选项内容对应的文字



    private ViewHolder holder = null;
    private class ViewHolder{
        TextView TvItemIndex;//大题文本题干
        TextView TvItemContent;//大题文本题干
        LinearLayout LayoutOptions;//选项显示区
        LinearLayout LayoutAnalysis;//答案显示区
        LinearLayout LayoutScore;//回看得分
//        View ViewLineVertical4;//回看得分竖线
        TextView TvAnswer;//正确答案
        TextView TvStuAnswer;//学生答案
        TextView TvScore;//得分
        TextView TvAnalysis;//解析

        LinearLayout LayoutClassicExample;//经典案例显示区
        LinearLayout LayoutClassicMenu;//参考答案及解析按钮
        ImageView IvClassic;//参考答案及解析箭头
        LinearLayout LayoutClassic;//参考答案及解析显示区
        TextView TvClassicAnswer;//参考答案
        TextView TvClassicAnalysis;//解析

        private ViewHolder(View convertView) {
            TvItemIndex = (TextView) convertView.findViewById(R.id.tv_item_index);
            TvItemContent = (TextView) convertView.findViewById(R.id.tv_item_content);
            LayoutOptions = (LinearLayout) convertView.findViewById(R.id.layout_options);
            LayoutAnalysis= (LinearLayout) convertView.findViewById(R.id.layout_analysis);
            LayoutScore = (LinearLayout) convertView.findViewById(R.id.layout_score);
//            ViewLineVertical4 = (View) convertView.findViewById(R.id.line_vertical_4);
            TvAnswer = (TextView) convertView.findViewById(R.id.tv_answer);
            TvStuAnswer = (TextView) convertView.findViewById(R.id.tv_stuanswer);
            TvScore = (TextView) convertView.findViewById(R.id.tv_score);
            TvAnalysis = (TextView) convertView.findViewById(R.id.tv_analysis);

            LayoutClassicExample = (LinearLayout) convertView.findViewById(R.id.layout_classic_example);
            LayoutClassicMenu = (LinearLayout) convertView.findViewById(R.id.layout_classic_menu);
            LayoutClassicMenu.setOnClickListener(new clickListener());
            IvClassic = (ImageView) convertView.findViewById(R.id.iv_classic);
            LayoutClassic = (LinearLayout) convertView.findViewById(R.id.layout_classic);
            TvClassicAnswer = (TextView) convertView.findViewById(R.id.tv_classic_answer);
            TvClassicAnalysis = (TextView) convertView.findViewById(R.id.tv_classic_analysis);
        }
    }

    private CustomAnswerChoiceView[] ChoiceAnswer;//选项信息


    public AnswerWxxzAdapter(Context context, int sumItem, int paperID,int optionID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.SumItem = sumItem;
        this.PaperID = paperID;
        this.OptionID = optionID;
        this.ModelFrom = modelFrom;
    }

    @Override
    public int getCount() {
        return SumItem;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_answer_wxxz_item, null);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        /*
        * 获取试题相关信息
        * */
        getQuesInfor();

        /*
        * 展示作答区内容及实现作答流程
        * */
        showQuesInfor();

        /*
        * 已提交状态下，初始化答案解析
        * */
        showAnalysis();

        return convertView;
    }

    /*
    * 获取试题相关信息
    * */
    private void getQuesInfor(){

        tvBlack = mContext.getResources().getColor(R.color.black);
        tvBlue = mContext.getResources().getColor(R.color.blue);
        tvWhite = mContext.getResources().getColor(R.color.white);
        tvGreen = mContext.getResources().getColor(R.color.green);
        tvRed = mContext.getResources().getColor(R.color.red);
//        btnWhite = R.drawable.round_white;
//        btnBlue = R.drawable.round_blue;
//        btnGreen = R.drawable.round_green;
//        btnRed = R.drawable.round_red;
        btnWhite = R.mipmap.option_normal;
        btnBlue = R.drawable.round_blue;
        btnGreen = R.mipmap.option_right;
        btnRed = R.mipmap.option_wrong;

        if(ModelFrom== PaperDef.FROM_BASE_REVIEW) {

            //试卷的作答状态
            state = InforBasicReview.getState();
            //小题编号
            itemIndex = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getItemIndex();
            //获取大题题干内容
            itemContent = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getItemContent();
            //本题是否可自评
            isAssess = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getIsAssess();
            //选项个数
            sumOption = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getOptionList().size();
            //用户答案
            stuAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAnswer();
            //正确答案
            answer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getAnswer();
            //自评/机评结果
            stuAssess = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAssess();
            //试题总分值
            score = InforBasicReview.getPaperContent().get(PaperID).getScore();
            //答案解析
            analysis =  InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getAnalysis();
            //小题数量
            totalItemCount = InforBasicReview.getPaperContent().get(PaperID).getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOptionIndex();
                option[i] = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOption();
            }

            int totalItemCount = InforBasicReview.getPaperContent().get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if(i==0){
                    stuAnswerAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforBasicReview.getPaperContent().get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);

        }else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW){
            //试卷的作答状态
            state = InforDifficultReview.getState();
            //小题编号
            itemIndex = InforDifficultReview.getQueList().get(OptionID).getItemIndex();
            //获取大题题干内容
            itemContent = InforDifficultReview.getQueList().get(OptionID).getItemContent();
            //本题是否可自评
            isAssess = InforDifficultReview.getQueList().get(OptionID).getIsAssess();
            //选项个数
            sumOption = InforDifficultReview.getQueList().get(OptionID).getOptionList().size();
            //用户答案
            stuAnswer = InforDifficultReview.getQueList().get(OptionID).getStuAnswer();
            //正确答案
            answer = InforDifficultReview.getQueList().get(OptionID).getAnswer();
            //自评/机评结果
            stuAssess = InforDifficultReview.getQueList().get(OptionID).getStuAssess();
            //试题总分值
            score = InforDifficultReview.getScore();
            //答案解析
            analysis =  InforDifficultReview.getQueList().get(OptionID).getAnalysis();
            //小题数量
            totalItemCount = InforDifficultReview.getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = InforDifficultReview.getQueList().get(OptionID).getOptionList().get(i).getOptionIndex();
                option[i] = InforDifficultReview.getQueList().get(OptionID).getOptionList().get(i).getOption();
            }

            int totalItemCount = InforDifficultReview.getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if(i==0){
                    stuAnswerAll = InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforDifficultReview.getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAssess();
                }
            }

            InforDifficultReview.setStuAnswerOldAll(stuAnswerAll);
            InforDifficultReview.setStuAssessOldAll(stuAssessAll);
            InforDifficultReview.setStuAnswerNewAll(stuAnswerAll);
            InforDifficultReview.setStuAssessNewAll(stuAssessAll);

        }else if(ModelFrom==PaperDef.FROM_GUESS_REVIEW){
            //试卷的作答状态
            state = InforGuessTesting.getState();
            //小题编号
            itemIndex = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getItemIndex();
            //获取大题题干内容
            itemContent = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getItemContent();
            //本题是否可自评
            isAssess = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getIsAssess();
            //选项个数
            sumOption = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getOptionList().size();
            //用户答案
            stuAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAnswer();
            //正确答案
            answer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getAnswer();
            //自评/机评结果
            stuAssess = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAssess();
            //试题总分值
            score = InforGuessTesting.getPaperContent().get(PaperID).getScore();
            //答案解析
            analysis =  InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getAnalysis();
            //小题数量
            totalItemCount = InforGuessTesting.getPaperContent().get(PaperID).getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOptionIndex();
                option[i] = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOption();
            }

            int totalItemCount = InforGuessTesting.getPaperContent().get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if(i==0){
                    stuAnswerAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforGuessTesting.getPaperContent().get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);
        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG){

            //试卷的作答状态
            state = InforWrongQues.get(PaperID).getState();
            Log.e("===state===", "===PaperID=="+PaperID+"===state===999===" + state);
            //小题编号
            itemIndex = InforWrongQues.get(PaperID).getQueList().get(OptionID).getItemIndex();
            //获取大题题干内容
            itemContent = InforWrongQues.get(PaperID).getQueList().get(OptionID).getItemContent();
            //选项个数
            sumOption = InforWrongQues.get(PaperID).getQueList().get(OptionID).getOptionList().size();
            //用户答案
            stuAnswer = InforWrongQues.get(PaperID).getQueList().get(OptionID).getStuAnswer();
            //正确答案
            answer = InforWrongQues.get(PaperID).getQueList().get(OptionID).getAnswer();
            //自评/机评结果
            stuAssess = InforWrongQues.get(PaperID).getQueList().get(OptionID).getStuAssess();
            //试题总分值
            score = InforWrongQues.get(PaperID).getScore();
            //答案解析
            analysis =  InforWrongQues.get(PaperID).getQueList().get(OptionID).getAnalysis();
            //小题数量
            totalItemCount = InforWrongQues.get(PaperID).getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = InforWrongQues.get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOptionIndex();
                option[i] = InforWrongQues.get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOption();
            }

            int totalItemCount = InforWrongQues.get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if(i==0){
                    stuAnswerAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforWrongQues.get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforWrongQues.get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforWrongQues.get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforWrongQues.get(PaperID).setStuAssessNewAll(stuAssessAll);

        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG_History||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG_History){

            //试卷的作答状态
            state = InforHistoryWrongQues.get(PaperID).getState();
            Log.e("===state===", "===PaperID=="+PaperID+"===state===999===" + state);
            //小题编号
            itemIndex = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getItemIndex();
            //获取大题题干内容
            itemContent = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getItemContent();
            //选项个数
            sumOption = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getOptionList().size();
            //用户答案
            stuAnswer = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getStuAnswer();
            //正确答案
            answer = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getAnswer();
            //自评/机评结果
            stuAssess = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getStuAssess();
            //试题总分值
            score = InforHistoryWrongQues.get(PaperID).getScore();
            //答案解析
            analysis =  InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getAnalysis();
            //小题数量
            totalItemCount = InforHistoryWrongQues.get(PaperID).getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOptionIndex();
                option[i] = InforHistoryWrongQues.get(PaperID).getQueList().get(OptionID).getOptionList().get(i).getOption();
            }

            int totalItemCount = InforHistoryWrongQues.get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            for (int i = 0; i < totalItemCount; i++) {
                if(i==0){
                    stuAnswerAll = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforHistoryWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }
            }
            InforHistoryWrongQues.get(PaperID).setStuAnswerOldAll(stuAnswerAll);
            InforHistoryWrongQues.get(PaperID).setStuAssessOldAll(stuAssessAll);
            InforHistoryWrongQues.get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforHistoryWrongQues.get(PaperID).setStuAssessNewAll(stuAssessAll);

        }else if(ModelFrom==PaperDef.FROM_FAVOURITE_REVIEW){
            //试卷的作答状态
            state = InforFavoritesPage.getState();
            //小题编号
            itemIndex = InforFavoritesPage.getQueList().get(OptionID).getItemIndex();
            //获取大题题干内容
            itemContent = InforFavoritesPage.getQueList().get(OptionID).getItemContent();
            //选项个数
            sumOption = InforFavoritesPage.getQueList().get(OptionID).getOptionList().size();
            //用户答案
            stuAnswer = InforFavoritesPage.getQueList().get(OptionID).getStuAnswer();
            //正确答案
            answer = InforFavoritesPage.getQueList().get(OptionID).getAnswer();
            //自评/机评结果
            stuAssess = InforFavoritesPage.getQueList().get(OptionID).getStuAssess();
            //试题总分值
            score = InforFavoritesPage.getScore();
            //答案解析
            analysis =  InforFavoritesPage.getQueList().get(OptionID).getAnalysis();
            //小题数量
            totalItemCount = InforFavoritesPage.getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = InforFavoritesPage.getQueList().get(OptionID).getOptionList().get(i).getOptionIndex();
                option[i] = InforFavoritesPage.getQueList().get(OptionID).getOptionList().get(i).getOption();
            }

        }
    }

    /*
    * 展示试题信息
    * */
    Handler htmlHandlerItemContent = new Handler();
    private void showQuesInfor(){
        holder.TvItemIndex.setText("("+itemIndex+")");
        /*
        * 显示题目题干
        * */
        itemContent = StringEscapeUtils.unescapeXml(itemContent);
        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                final Spanned tvItemContent = Html.fromHtml(itemContent, Control.imgGetter,null);
                htmlHandlerItemContent.post(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        holder.TvItemContent.setText(tvItemContent);
                    }
                });
            }
        }).start();

        /*
        * 显示选项内容
        * */
        ChoiceAnswer = new CustomAnswerChoiceView[sumOption];
        for(int i =0;i<sumOption;i++){
            ChoiceAnswer[i] = new CustomAnswerChoiceView(mContext);
            ChoiceAnswer[i].setAnswerChoice(optionIndex[i],tvBlack,btnWhite,option[i],tvBlack);

            final int finalI = i;
            ChoiceAnswer[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e("===state===", "======state===000===" + state);
                    if (state==2 ||(PaperID==0&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG))||
                            (PaperID==1&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG))||
                            ModelFrom==PaperDef.FROM_FAVOURITE_REVIEW) {
                        return;
                    }else {

                        if(ModelFrom==PaperDef.FROM_BASE_REVIEW){
                            stuAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAnswer();
                        }else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW){
                            stuAnswer = InforDifficultReview.getQueList().get(OptionID).getStuAnswer();
                        }else if(ModelFrom==PaperDef.FROM_GUESS_REVIEW){
                            stuAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAnswer();
                        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG){
                            stuAnswer = InforWrongQues.get(PaperID).getQueList().get(OptionID).getStuAnswer();
                        }

                        for (int k = 0; k < sumOption; k++) {
                            if (finalI == k) {
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                setStuAnswer(Control.asciiToString(k + 65));
                            } else {
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                            }
                        }
                    }
                }
            });

            ChoiceAnswer[i].BtnChoice.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e("===state===", "======state===111===" + state);
                    if (state==2 ||(PaperID==0&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG))||
                            (PaperID==1&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG))||
                            ModelFrom==PaperDef.FROM_FAVOURITE_REVIEW) {
                        return;
                    }else {

                        if(ModelFrom==PaperDef.FROM_BASE_REVIEW){
                            stuAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAnswer();
                        }else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW){
                            stuAnswer = InforDifficultReview.getQueList().get(OptionID).getStuAnswer();
                        }else if(ModelFrom==PaperDef.FROM_GUESS_REVIEW){
                            stuAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).getStuAnswer();
                        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG){
                            stuAnswer = InforWrongQues.get(PaperID).getQueList().get(OptionID).getStuAnswer();
                        }

                        for (int k = 0; k < sumOption; k++) {
                            if (finalI == k) {
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                setStuAnswer(Control.asciiToString(k + 65));
                            } else {
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                            }
                        }
                    }
                }
            });

            holder.LayoutOptions.addView(ChoiceAnswer[i]);

        }

        if (state==2 ||(PaperID==0&&ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG)||(PaperID==0&&ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG)) {
            //已提交
            int currentOption = -1;
            int currentTrueOption = -1;
            if(!stuAnswer.equals("")){
                currentOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                if (stuAnswer.equals(answer)) {
                    for (int k = 0; k < sumOption; k++) {
                        if (currentOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                        }
                    }
                } else if (!stuAnswer.equals(answer)) {
                    for (int k = 0; k < sumOption; k++) {

                        if (currentOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnRed,option[k],tvRed);
                        }
                        if(currentTrueOption == k){
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                        }
                    }
                }
            }
        }else{
            //未提交
            if (!stuAnswer.equals("")) {

                int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                Log.e("==AAA=11=", "======trueOption======" + trueOption);

                for (int k = 0; k < sumOption; k++) {
                    if (trueOption == k) {
                        ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                    }
                }

            }

        }

    }


    /*
    * 已提交状态试题分析部分内容展示
    * */
    private void showAnalysis() {

        if(ModelFrom==PaperDef.FROM_FAVOURITE_REVIEW||
                (PaperID==1&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG))){
            holder.LayoutAnalysis.setVisibility(View.GONE);
            holder.LayoutClassicExample.setVisibility(View.VISIBLE);

            holder.LayoutClassic.setVisibility(View.GONE);
            holder.TvClassicAnswer.setText(answer);
            if(analysis.equals("")){
                holder.TvClassicAnalysis.setText("暂无解析");
            }else {
                analysis = StringEscapeUtils.unescapeXml(analysis);
                holder.TvClassicAnalysis.setText(Html.fromHtml(analysis));
            }
        }else {

//        if(PaperID==1&&(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG)){
//            holder.LayoutAnalysis.setVisibility(View.GONE);
//            holder.LayoutClassicExample.setVisibility(View.VISIBLE);
//
//            holder.LayoutClassic.setVisibility(View.GONE);
//            holder.TvClassicAnswer.setText(answer);
//            if(analysis.equals("")){
//                holder.TvClassicAnalysis.setText("暂无解析");
//            }else {
//                holder.TvClassicAnalysis.setText(analysis);
//            }
//
//        }else{
//            holder.LayoutClassicExample.setVisibility(View.GONE);
//        }

            if (state == 2 || (PaperID == 0 && ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG)) {

                if (ModelFrom == PaperDef.FROM_BASE_REVIEW || ModelFrom == PaperDef.FROM_GUESS_REVIEW) {
                    holder.LayoutScore.setVisibility(View.VISIBLE);
//                    holder.ViewLineVertical4.setVisibility(View.VISIBLE);
                } else {
                    holder.LayoutScore.setVisibility(View.GONE);
//                    holder.ViewLineVertical4.setVisibility(View.GONE);
                }
                holder.LayoutAnalysis.setVisibility(View.VISIBLE);

                holder.TvAnswer.setText(answer);
                if (stuAnswer.equals("")) {
                    stuAnswer = "未作答";
                }
                if (stuAnswer.equals(answer)) {
                    holder.TvStuAnswer.setTextColor(mContext.getResources().getColor(R.color.green));
                } else {
                    holder.TvStuAnswer.setTextColor(mContext.getResources().getColor(R.color.red));
                }
                holder.TvStuAnswer.setText(stuAnswer);

                double stuScore = 0;
                if (stuAnswer.equals(answer)) {
                    stuScore = score * 1.0;
                } else {
                    stuScore = score * 0;
                }
                holder.TvScore.setText(String.valueOf(stuScore / totalItemCount) + "分");

                if (analysis.equals("")) {
                    analysis = "暂无解析";
                }
                holder.TvAnalysis.setText(analysis);

            } else {

                holder.LayoutAnalysis.setVisibility(View.GONE);

            }
            holder.LayoutClassicExample.setVisibility(View.GONE);
        }

    }

    /*
    * 写入作答信息
    * */
    private void setStuAnswer(String strStuAnswer){
        if(ModelFrom == PaperDef.FROM_BASE_REVIEW){
            InforBasicReview.getPaperContent().get(PaperID).getQueList().get(OptionID).setStuAnswer(strStuAnswer);
            int totalItemCount = InforBasicReview.getPaperContent().get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                thisAnswer = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getAnswer();
                thisStuAssess = InforBasicReview.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforBasicReview.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforBasicReview.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);
            InforBasicReview.getPaperContent().get(PaperID).setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforBasicReview.getPaperContent().get(PaperID).setAnsweredItemCount(quesAnsweredItemCount);

        }else if(ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW){

            InforDifficultReview.getQueList().get(OptionID).setStuAnswer(strStuAnswer);
            int totalItemCount = InforDifficultReview.getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforDifficultReview.getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforDifficultReview.getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforDifficultReview.getQueList().get(i).getStuAnswer();
                thisAnswer = InforDifficultReview.getQueList().get(i).getAnswer();
                thisStuAssess = InforDifficultReview.getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforDifficultReview.setStuAnswerNewAll(stuAnswerAll);
            InforDifficultReview.setStuAssessNewAll(stuAssessAll);
            InforDifficultReview.setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforDifficultReview.setAnsweredItemCount(quesAnsweredItemCount);

        }else if(ModelFrom==PaperDef.FROM_GUESS_REVIEW){
            InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(OptionID).setStuAnswer(strStuAnswer);
            int totalItemCount = InforGuessTesting.getPaperContent().get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAnswer();
                thisAnswer = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getAnswer();
                thisStuAssess = InforGuessTesting.getPaperContent().get(PaperID).getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforGuessTesting.getPaperContent().get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforGuessTesting.getPaperContent().get(PaperID).setStuAssessNewAll(stuAssessAll);
            InforGuessTesting.getPaperContent().get(PaperID).setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforGuessTesting.getPaperContent().get(PaperID).setAnsweredItemCount(quesAnsweredItemCount);
        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG){

            InforWrongQues.get(PaperID).getQueList().get(OptionID).setStuAnswer(strStuAnswer);
            int totalItemCount = InforWrongQues.get(PaperID).getTotalItemCount();
            String stuAnswerAll = "";
            String stuAssessAll = "";
            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int quesAnsweredItemCount = 0;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    stuAnswerAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }else{
                    stuAnswerAll = stuAnswerAll+"#$*#"+InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                    stuAssessAll = stuAssessAll+"#$*#"+InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                }
                thisStuAnswer = InforWrongQues.get(PaperID).getQueList().get(i).getStuAnswer();
                thisAnswer = InforWrongQues.get(PaperID).getQueList().get(i).getAnswer();
                thisStuAssess = InforWrongQues.get(PaperID).getQueList().get(i).getStuAssess();
                if(!thisStuAssess.equals("")) {
                    if (thisStuAssess.equals("正确") || thisStuAssess.equals("优秀")||thisStuAssess.equals("一般")) {
                        totalItemCountTrue++;
                    }
                }else {
                    if (thisStuAnswer.equals(thisAnswer)) {
                        totalItemCountTrue++;
                    }
                }

                if(!thisStuAnswer.equals("")||!thisStuAssess.equals("")){
                    quesAnsweredItemCount++;
                }

            }

            InforWrongQues.get(PaperID).setStuAnswerNewAll(stuAnswerAll);
            InforWrongQues.get(PaperID).setStuAssessNewAll(stuAssessAll);
            InforWrongQues.get(PaperID).setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(totalItemCount)));
            InforWrongQues.get(PaperID).setAnsweredItemCount(quesAnsweredItemCount);

        }
    }

    /**************************************************************************************************/
    /**************************************************************************************************/

    private class clickListener implements View.OnClickListener {
        public void onClick(View v) {
            if (holder.LayoutClassic.getVisibility() == GONE) {
                animationIvOpen();
                holder.LayoutClassic.setVisibility(View.VISIBLE);
            } else {
                animationIvClose();
                holder.LayoutClassic.setVisibility(View.GONE);
            }
        }
    }

    private void animationIvOpen() {
        RotateAnimation animation = new RotateAnimation(0, 180,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        animation.setFillAfter(true);
        animation.setDuration(100);
        holder.IvClassic.startAnimation(animation);
    }

    private void animationIvClose() {
        RotateAnimation animation = new RotateAnimation(180, 0,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        animation.setFillAfter(true);
        animation.setDuration(100);
        holder.IvClassic.startAnimation(animation);
    }
    /*********************************************************************************************************/
    /*********************************************************************************************************/


}